<?php
/* @var $this PageController */
/* @var $model Page */
/* @var $form TbActiveForm */
?>
<link rel="stylesheet" href="<?php echo Yii::app()->theme->baseUrl; ?>/assets/css/magicsuggest-1.3.1.css">
<script type="text/javascript" src="<?php echo Yii::app()->theme->baseUrl; ?>/assets/js/magicsuggest-1.3.1.js"></script>
<div class="form">

	<?php
	$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
		'id' => 'page-form',
		// Please note: When you enable ajax validation, make sure the corresponding
		// controller action is handling ajax validation correctly.
		// There is a call to performAjaxValidation() commented in generated controller code.
		// See class documentation of CActiveForm for details on this.
		'htmlOptions' => array('enctype' => 'multipart/form-data'),
		'enableClientValidation' => true,
		'clientOptions' => array(
			'validateOnSubmit' => true,
		),
//		'htmlOptions'=>array('enctype' => 'multipart/form-data'),
	));
	foreach (Yii::app()->params['regions'] as $key => $value) {
		$regions[$value['regionId']] = $value['regionTitle'];
	}
	?>

	<?php echo $form->errorSummary($model); ?>            

	<?php if ($model->isNewRecord) $this->widget('application.modules.admin.widgets.GetChilds', array('updatedHidden' => 'hidden-id')); ?>

	<?php echo $form->hiddenField($model, 'pageParent', array('id' => 'hidden-id')); ?>    

	<?php echo $form->dropDownListControlGroup($model, 'pageType', array('actions' => 'Акция', 'news' => 'Новость', 'articles' => 'Статья', 'vacancies' => 'Вакансии', 'info' => 'Информационная страница', 'brand' => 'Бренд', 'model' => 'Модель', 'category' => 'Категория', 'list' => 'Список', 'servcenter' => 'Сервисный центр', 'service' => 'Услуги', 'contact' => 'Контакт')); ?>

	<?php echo $form->dropDownListControlGroup($model, 'pageItemId', $regions, array('span' => 5, 'maxlength' => 255)); ?>

	<?php echo $form->textFieldControlGroup($model, 'pageTitle', array('span' => 5, 'maxlength' => 255)); ?>

	<?php echo $form->textFieldControlGroup($model, 'pageFullTitle', array('span' => 5, 'maxlength' => 255)); ?>

	<?php echo $form->textFieldControlGroup($model, 'pageUrl', array('span' => 5, 'maxlength' => 255)); ?>

	<?php echo $form->textAreaControlGroup($model, 'pageContentShort', array('rows' => 6, 'span' => 8)); ?>

	<?php echo $form->textAreaControlGroup($model, 'pageContentFull', array('rows' => 6, 'span' => 8)); ?>

	<?php echo $form->textAreaControlGroup($model, 'pageDescription', array('rows' => 6, 'span' => 8)); ?>

	<?php echo $form->dropDownListControlGroup($model, 'pageActive', array(0 => 'Отключена', '1' => 'Активна')); ?>

	<?php echo $form->textFieldControlGroup($model, 'pageAuthor', array('span' => 5, 'maxlength' => 11)); ?>

	<?php echo $form->textFieldControlGroup($model, 'pageSort', array('span' => 5)); ?>

	<?php echo $form->textFieldControlGroup($model, 'pageAction', array('span' => 5, 'maxlength' => 255)); ?>

	<?php echo $form->labelEx($model, 'pageCreateDate'); ?>
	<?php
	$this->widget('zii.widgets.jui.CJuiDatePicker', array(
		'model' => $model,
		//'value' => '34',
		'attribute' => 'pageCreateDate',
		'options' => array("dateFormat" => 'dd-mm-yy'),
	));
	?>

	<?php echo $form->error($model, 'pageCreateDate'); ?>

	<?php //echo $form->textFieldControlGroup($model, 'pageCreateDate', array('span' => 5, 'maxlength' => 255, 'value' => time())); ?>

	<?php echo $form->fileFieldControlGroup($model, 'pageImages', array('span' => 5, 'maxlength' => 255)); ?>

	<?php
	$style = ' style="display:none;" ';
	if (!$model->isNewRecord && $model->pageType == 'contact')
		$style = '';
	?>
	<div id="contact_more_fields"  <?php echo $style; ?>>
		<div class="control-group">
			<label for="Page_pageTitle_1" class="control-label required">Название точки на главной <span class="required">*</span></label>
			<div class="controls">
				<input type="text" class="span5" name="pageTitle[mainTitle]" maxlength="255" value="<?php echo CHtml::encode($pageTitle['mainTitle']); ?>">
			</div>
		</div>
		<div class="control-group">
			<label for="Page_pageTitle_2" class="control-label required">Название точки в блок <span class="required">*</span></label>
			<div class="controls">
				<input type="text" class="span5" name="pageTitle[blockTitle]" maxlength="255" value='<?php echo CHtml::encode($pageTitle['blockTitle']); ?>'>
			</div>
		</div>
		<div class="control-group">
			<label for="Page_pageTitle_3" class="control-label required">Класс для метро <span class="required">*</span></label>
			<div class="controls">
				<input type="text" class="span5" name="pageTitle[metroCss]" maxlength="255" value='<?php echo CHtml::encode($pageTitle['metroCss']); ?>'>
			</div>
		</div>
                <div class="control-group">
			<label for="Page_pageTitle_4" class="control-label required">телефон <span class="required">*</span></label>
			<div class="controls">
                            <input type="text" class="span5" name="pageTitle[phone]" maxlength="255" value='<?php echo isset($pageTitle['phone']) ? CHtml::encode($pageTitle['phone']) : ''; ?>'>
			</div>
		</div>
	</div>
	<div id="brands" style="display: none;">
		<div class="control-group">
			<label>Прикреплённые бренды <span class="required">*</span></label>
			<div class="controls">
				<input type="text" class="span5" name="brands" maxlength="255" id="ms-cats">
			</div>
		</div>
		<br /><br /><br />
	</div>

	<div class="form-actions">
		<?php
		echo TbHtml::submitButton($model->isNewRecord ? 'Создать' : 'Сохранить', array(
			'color' => TbHtml::BUTTON_COLOR_PRIMARY,
			'size' => TbHtml::BUTTON_SIZE_LARGE,
		));
		?>
	</div>

	<?php $this->endWidget(); ?>

</div><!-- form -->
<script>
	$(document).ready(function()
	{
		<?php if (!$model->isNewRecord && $model->pageType == 'servcenter'): ?>
		$('#brands').show();
		<?php endif; ?>

		var ms = $('#ms-cats').magicSuggest({
			name: 'brands',
			width: 350,
			//sortOrder: 'title',
			selectionStacked: false,
			selectionPosition: 'right',
			displayField: 'title',
			//value: <?php if (!$model->isNewRecord) echo $model->pageDescription; ?>,
			data: <?php echo $model->getProductCategory(); ?>
		});

		$('#Page_pageItemId').parent().parent().hide();

		$('#Page_pageTitle').keyup(function() {
			$('#Page_pageUrl').val(cyr2lat($(this).val(), mobi03.url));

		});

		$('body').on('change', '#Page_pageType', function()
		{
			$('#Page_pageAction').val($(this).val());
			
			$(this).val() == 'servcenter' ? $('#brands').show() : $('#brands').hide();
			
			if ($(this).val() == 'contact')
			{
				$('#Page_pageItemId').parent().parent().show();
				$('#contact_more_fields').show();
			} else
			{
				$('#Page_pageItemId').parent().parent().hide();
				$('#contact_more_fields').hide();
			}
		});
	});
</script>
